package com.zhang.sdk.ui.dialog.bottom;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.zhang.sdk.R;

import java.util.List;

/*****************************************************
 * 版权信息: 2019 北京振中电子有限公司版权所有
 * 创建作者: zhang.x
 * 创建日期: 2020/5/18 13:58
 * ****************************************************
 * 更改记录: 更新人:    更新时间:    更新概要:
 *
 * ****************************************************
 *  类功能说明: 
 * ****************************************************/
public class RvBottomMenuAdapter extends RecyclerView.Adapter<RvBottomMenuAdapter.ItemViewHolder>{
    private Context mContext;
    private List<BottomMenuItem> mData;
    private OnMenuItemClickListener listener;

    public RvBottomMenuAdapter(Context mContext, List<BottomMenuItem> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    public void setData(List<BottomMenuItem> mData) {
        this.mData = mData;
        notifyDataSetChanged();
    }

    public void setOnItemClickListener(OnMenuItemClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_rv_bottom_menu, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder holder, final int position) {
        holder.tvItem.setText(mData.get(position).getmMenuName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onItemClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    static class ItemViewHolder extends RecyclerView.ViewHolder {
        private TextView tvItem;

        public ItemViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItem = itemView.findViewById(R.id.tv_menu_name);
        }
    }
}
